/*
package com.example.rumen;

import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class Appshop extends AppCompatActivity {

    //把新导入的图片导入
    int imags[] = new int[]{R.drawable.qq1, R.drawable.wangyiyun, R.drawable.bilibili, R.drawable.voa, R.drawable.weixin2,
            R.drawable.ximalaya, R.drawable.taobao22, R.drawable.qq1, R.drawable.wangyiyun, R.drawable.bilibili, R.drawable.voa,
            R.drawable.weixin2, R.drawable.ximalaya};
    String names[] = new String[]{"QQ", "网易云音乐", "哔哩哔哩", "VOA", "微信", "喜马拉雅", "淘宝",
            "QQ", "网易云音乐", "哔哩哔哩", "VOA", "微信", "喜马拉雅"};
    String message[] = new String[]{"随时随地的满足", "去世界任何你想去的地方", "用英语玩转身边生活", "聆听世界精彩你我世界", "直击你我心灵", "足不出户拥有精彩", "直播带货停不下来", "去世界任何你想去的地方", "走向世界聆听世界声音", "属于你的美妙时刻", "联系你我心灵", "足不出户拥有精彩", "聆听你我心声"};

    private ListView list_view;
    private ArrayList<Map<String, Object>> arrayList;
    private SimpleAdapter simpleAdapter;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_appshop);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        //1.准备框架
        list_view = findViewById(R.id.listview_0325);
        //2.准备数据,相当于一列空的列车
        arrayList = new ArrayList<>();
        for (int i = 0; i < imags.length; i++) {
            Map<String, Object> map = new HashMap<String, Object>();
            //从001开始增长
//            String num = String.format("%03d", i + 1);
//            map.put(num, imags[i]);
            map.put("001", imags[i]);
            map.put("002", names[i]);
            map.put("003", message[i]);
            arrayList.add(map);
        }
        //3.准备布局文件
        //4.实现数组适配器
        simpleAdapter = new SimpleAdapter(getApplicationContext(), arrayList, R.layout.simple,
                new String[]{"001", "002", "003"}, new int[]{R.id.imageView_0325, R.id.textView_0325_1, R.id.textView_0325_2}) {

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {

                View view = super.getView(position, convertView, parent);

                Button btn_download = view.findViewById(R.id.button_0325_download);
                btn_download.setTag(position);
                btn_download.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
//                        Toast.makeText(getApplicationContext(), "下载" + names[(int) v.getTag()], Toast.LENGTH_SHORT).show();

                        myAscy myAscy = new myAscy(Appshop.this);
                        myAscy.execute(new Integer(0));
//                        txt.setText("任务下载中");
                        Toast.makeText(getApplicationContext(),"任务下载中",Toast.LENGTH_SHORT).show();


                    }
                });

                return view;
            }
        };
        //5.加载适配器
        list_view.setAdapter(simpleAdapter);
    }
}

class myAscy extends AsyncTask<Integer,Integer,String> {

    private ProgressDialog progressDialog;
    private Context context;

    public myAscy(Context context){

        this.context=context;

    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        progressDialog = new ProgressDialog(context);
        progressDialog.setTitle("★温馨提示★");
        progressDialog.setMessage("任务正在下载中。。。");
        progressDialog.setMax(100);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        progressDialog.show();
    }

    @Override
    protected String doInBackground(Integer... integers) {
        int i=integers[0];
        while(i<100){

            i++;
            publishProgress(i);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }

        return "下载完成";
    }

    @Override
    protected void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);
        progressDialog.setProgress(values[0]);
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);

        progressDialog.dismiss();
//         Toast.makeText(getApplicationContext(),item[pos]+"下载完成",Toast.LENGTH_SHORT).show();？
//        txt.setText("下载完成");
        Toast.makeText(context.getApplicationContext(),"下载完成",Toast.LENGTH_SHORT).show();


    }
}
*/
package com.example.rumen;

import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class Appshop extends AppCompatActivity {

    //把新导入的图片导入
    int imags[] = new int[]{R.drawable.qq1, R.drawable.wangyiyun, R.drawable.bilibili, R.drawable.voa, R.drawable.weixin2,
            R.drawable.ximalaya, R.drawable.taobao22, R.drawable.qq1, R.drawable.wangyiyun, R.drawable.bilibili, R.drawable.voa,
            R.drawable.weixin2, R.drawable.ximalaya};
    String names[] = new String[]{"QQ", "网易云音乐", "哔哩哔哩", "VOA", "微信", "喜马拉雅", "淘宝",
            "QQ", "网易云音乐", "哔哩哔哩", "VOA", "微信", "喜马拉雅"};
    String message[] = new String[]{"随时随地的满足", "去世界任何你想去的地方", "用英语玩转身边生活", "聆听世界精彩你我世界", "直击你我心灵", "足不出户拥有精彩", "直播带货停不下来", "去世界任何你想去的地方", "走向世界聆听世界声音", "属于你的美妙时刻", "联系你我心灵", "足不出户拥有精彩", "聆听你我心声"};

    private ListView list_view;
    private ArrayList<Map<String, Object>> arrayList;
    private SimpleAdapter simpleAdapter;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_appshop);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        //1.准备框架
        list_view = findViewById(R.id.listview_0325);
        //2.准备数据,相当于一列空的列车
        arrayList = new ArrayList<>();
        for (int i = 0; i < imags.length; i++) {
            Map<String, Object> map = new HashMap<String, Object>();
            //从001开始增长
//            String num = String.format("%03d", i + 1);
//            map.put(num, imags[i]);
            map.put("001", imags[i]);
            map.put("002", names[i]);
            map.put("003", message[i]);
            arrayList.add(map);
        }
        //3.准备布局文件
        //4.实现数组适配器
        simpleAdapter = new SimpleAdapter(getApplicationContext(), arrayList, R.layout.simple,
                new String[]{"001", "002", "003"}, new int[]{R.id.imageView_0325, R.id.textView_0325_1, R.id.textView_0325_2}) {

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {

                View view = super.getView(position, convertView, parent);

                Button btn_download = view.findViewById(R.id.button_0325_download);
                btn_download.setTag(position);
                btn_download.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = (int) v.getTag();
                        // 传递当前位置到AsyncTask
                        myAscy myAscy = new myAscy(Appshop.this, pos, names);
                        myAscy.execute(new Integer(0));
                        Toast.makeText(getApplicationContext(), names[pos] + "任务下载中", Toast.LENGTH_SHORT).show();
                    }
                });

                return view;
            }
        };
        //5.加载适配器
        list_view.setAdapter(simpleAdapter);
    }
}

class myAscy extends AsyncTask<Integer, Integer, String> {

    private ProgressDialog progressDialog;
    private Context context;
    private int position; // 保存当前APP的位置
    private String[] appNames; // 保存所有APP的名称数组

    public myAscy(Context context, int position, String[] names) {
        this.context = context;
        this.position = position; // 存储位置信息
        this.appNames = names; // 存储名称数组
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        progressDialog = new ProgressDialog(context);
        progressDialog.setTitle("★温馨提示★");
        progressDialog.setMessage(appNames[position] + "正在下载中...");
        progressDialog.setMax(100);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        progressDialog.show();
    }

    @Override
    protected String doInBackground(Integer... integers) {
        int i = integers[0];
        while (i < 100) {
            i++;
            publishProgress(i);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return "下载完成";
    }

    @Override
    protected void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);
        progressDialog.setProgress(values[0]);
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        progressDialog.dismiss();
        // 使用position获取APP名称
        Toast.makeText(context.getApplicationContext(), appNames[position] + "下载完成", Toast.LENGTH_SHORT).show();
    }
}